<body>
<div class="modal inmodal" id="searchDisease" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h5 class="modal-title">搜索疾病</h5>
            </div>
            <div class="modal-body">
                <div class="ibox ">
                    <div class="ibox-content">
                        <div class="search-form">
                            <form>
                                <div class="form-group">
                                    <input type="text" placeholder="请输入疾病类别" name="searchDiseaseCategory"
                                           class="form-control input-lg" list="diseaseCategoryList">
                                    <datalist style="display:none;" id="diseaseCategoryList">
                                    </datalist>
                                </div>
                                <div class="input-group">
                                    <input type="text" placeholder="请输入疾病名称" name="searchDisease"
                                           class="form-control input-lg">
                                    <div class="input-group-btn">
                                        <button class="btn btn-lg btn-primary" type="button" id="searchNow">
                                            搜索
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="search-result" id="searchResult">
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="text-center">
                            <div class="btn-group" id="firstPageNum">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal inmodal" id="addPreModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">增加处方</h4>
            </div>
            <div class="modal-body">
                <input type="text" placeholder="请输入处方名称" name="preName"
                       class="form-control input-lg">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addPreName()" data-dismiss="modal">增加</button>
            </div>
        </div>
    </div>
</div>

<div class="modal inmodal" id="searchDrug" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h5 class="modal-title">搜索药品</h5>
            </div>
            <div class="modal-body">
                <div class="ibox ">
                    <div class="ibox-content">
                        <div class="search-form">
                            <form>
                                <div class="input-group">
                                    <input type="text" placeholder="请输入药品名称" name="searchDrug"
                                           class="form-control input-lg">
                                    <div class="input-group-btn">
                                        <button class="btn btn-lg btn-primary" type="button" id="searchDrugNow">
                                            搜索
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="search-result" id="searchDrugResult">
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="text-center">
                            <div class="btn-group" id="firstDrugPageNum">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="container">
        <div class="row">
            <div class="col-md-4" style="padding-right: 0px" id="patientSelectDiv">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-8">
                            <h4>患者选择：</h4>
                        </div>
                        <div class="col-sm-4">
                            <button class="btn btn-xs btn-primary" style="float: right"
                                    onclick="refreshPatientInfo()">
                                <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>
                            </button>
                        </div>
                    </div>

                    <!--                    <div class="form-inline">-->
                    <!--                        <label>患者名：</label>-->
                    <!--                        <div><input type="text"></div>-->
                    <!--                        <button type="button" class="btn btn-default">-->
                    <!--                            <i class="fa fa-search" aria-hidden="true"></i>-->
                    <!--                        </button></div>-->
                    <!--                    </div>-->
                </div>
                <div class="ibox-content">
                    <h5>未诊患者：</h5>
                    <div class="table-responsive">
                        <table class="table table-hover" id="patientNotDiagnose">
                            <thead>
                            <tr>
                                <th>病历号</th>
                                <th>姓名</th>
                                <th>年龄</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                    <h5>已诊患者：</h5>
                    <div class="table-responsive">
                        <table class="table table-hover" id="patientDiagnose">
                            <thead>
                            <tr>
                                <th>病历号</th>
                                <th>姓名</th>
                                <th>年龄</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="col-md-8" style="padding-left: 0px;background: white" id="patientFunctionDiv">
                    <div class="form-inline">
                        <button class="btn btn-lg btn-primary" id="diagnosingPatientRegistrationID" value="">隐藏患者栏
                        </button>
                        <h3 style="margin-left: 20px" id="diagnosingPatient"></h3>
                    </div>
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li><a class="nav-link active" data-toggle="tab" href="#tab-1">病历首页</a>
                        </li>
                        <li><a class="nav-link" data-toggle="tab" href="#tab-2" aria-controls="home">检查申请</a>
                        </li>
                        <li><a class="nav-link" data-toggle="tab" href="#tab-3" aria-controls="home">检验申请</a>
                        </li>
                        <li><a class="nav-link" data-toggle="tab" href="#tab-4" aria-controls="home">门诊确诊</a>
                        </li>
                        <li><a class="nav-link" data-toggle="tab" href="#tab-5" aria-controls="home">处置申请</a>
                        </li>
                        <li><a class="nav-link" data-toggle="tab" href="#tab-6" aria-controls="home">成药处方</a>
                        </li>
                        <li><a class="nav-link" data-toggle="tab" href="#tab-7" aria-controls="home">费用查询</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane active in">
                            <div class="panel-body">
                                <div class="ibox">
                                    <div class="ibox-content">
                                        <form id="medicalRecordInfo">
                                            <div class="container">
                                                <div class="row">
                                                    <div class="col-md-3 text-center">
                                                        <button class="btn btn-primary btn-xs" type="button"
                                                                onclick="submitMedicalRecord(this)">暂存
                                                        </button>
                                                    </div>
                                                    <div class="col-md-3 text-center">
                                                        <button class="btn btn-primary btn-xs" type="button"
                                                                onclick="submitMedicalRecord(this)">提交
                                                        </button>
                                                    </div>
                                                    <div class="col-md-3 text-center">
                                                        <button class="btn btn-primary btn-xs" type="reset">清空所有
                                                        </button>
                                                    </div>
                                                    <div class="col-md-3 text-center">
                                                        <button class="btn btn-primary btn-xs" type="reset">刷新</button>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="hr-line-dashed"></div>
                                            <div><label>病史内容：</label></div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">主诉：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordSaying"></div>
                                            </div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">现病史：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordCurtIllness"></div>
                                            </div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">现病治疗情况：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordTreat"></div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="col-sm-2 col-form-label">既往史：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordPreIllness"></div>
                                            </div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">过敏史：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordAllergy"></div>
                                            </div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">体格检查：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordCheck"></div>
                                            </div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">检察建议：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordCheckAdvice"></div>
                                            </div>
                                            <div class="form-group  row">
                                                <label class="col-sm-2 col-form-label">注意事项：</label>
                                                <div class="col-sm-10"><input type="text" class="form-control"
                                                                              name="medicalRecordWarn"></div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                <div class="ibox ">
                                    <div class="ibox-title">
                                        <div class="container">
                                            <div class="row">
                                                <div class="col-sm-10">
                                                    <h5>评估/诊断：</h5>
                                                    <button type="button" class="btn btn-info btn-xs"
                                                            style="float: right"
                                                            id="deleteConfirm">
                                                        删除
                                                    </button>
                                                </div>
                                                <div class="col-sm-2">
                                                    <button type="button" class="btn btn-info btn-xs"
                                                            style="float: right"
                                                            id="addConfirm" data-toggle="modal"
                                                            data-target="#searchDisease">
                                                        增加
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="ibox-content">
                                        <div class="table-responsive">
                                            <table class="table" id="confirmInfoTable">
                                                <thead>
                                                <tr>
                                                    <th><input type="checkbox" checked class="i-checks"
                                                               name="selectAllDisease"></th>
                                                    <th>ICD编码</th>
                                                    <th>名称</th>
                                                    <th></th>
                                                    <th>发病时间</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="tab-2" class="tab-pane fade">
                            <div class="panel-body">
                                <p>检查申请</p>
                            </div>
                        </div>
                        <div id="tab-3" class="tab-pane fade">
                            <div class="panel-body">
                                <p>检验申请</p>
                            </div>
                        </div>
                        <div id="tab-4" class="tab-pane fade">
                            <div class="panel-body">
                                <p>门诊确诊</p>
                            </div>
                        </div>
                        <div id="tab-5" class="tab-pane fade">
                            <div class="panel-body">
                                <p>处置申请</p>
                            </div>
                        </div>
                        <div id="tab-6" class="tab-pane fade">
                            <div class="panel-body">
                                <div class="ibox">
                                    <div class="ibox-content">
                                        <div class="container">
                                            <div class="row">
                                                <div class="col-md-8 text-right">
                                                    <div class="row">
                                                        <div class="col-md-2">
                                                            <button class="btn btn-primary btn-xs" type="button"
                                                                    id="addPre" data-toggle="modal"
                                                                    data-target="#addPreModal">增方
                                                            </button>
                                                        </div>
                                                        <div class="col-md-2">
                                                            <button class="btn btn-primary btn-xs" type="button">删方
                                                            </button>
                                                        </div>
                                                        <div class="col-md-2">
                                                            <button class="btn btn-primary btn-xs" type="button"
                                                                    onclick="makePre()">开立
                                                            </button>
                                                        </div>
                                                        <div class="col-md-2">
                                                            <button class="btn btn-primary btn-xs" type="button">作废
                                                            </button>
                                                        </div>
                                                        <div class="col-md-2">
                                                            <button class="btn btn-primary btn-xs" type="reset">刷新
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-4 text-center">
                                                    <button class="btn btn-primary btn-xs" type="button" id="addDrug"
                                                            style="margin-right: 10px" data-toggle="modal"
                                                            data-target="#searchDrug">
                                                        增药
                                                    </button>
                                                    <button class="btn btn-primary btn-xs" type="button">
                                                        删药
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="container">
                                            <div class="row">
                                                <div class="col-sm-3">
                                                    <div class="ibox ">
                                                        <div class="ibox-title">
                                                            <h5>处方：</h5>
                                                        </div>
                                                        <div class="ibox-content">
                                                            <div class="table-responsive">
                                                                <table class="table"
                                                                       id="preInfo">
                                                                    <thead>
                                                                    <tr>
                                                                        <th></th>
                                                                        <th>名称</th>
                                                                        <th>状态</th>
                                                                    </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-sm-9">
                                                    <div class="ibox ">
                                                        <div class="ibox-title">
                                                            <h5>本处方明细：</h5>
                                                        </div>
                                                        <div class="ibox-content">
                                                            <div class="table-responsive">
                                                                <table class="table"
                                                                       id="preDetailInfo">
                                                                    <thead>
                                                                    <tr>
                                                                        <th><input type="checkbox" checked
                                                                                   class="i-checks"
                                                                                   name="selectAll"></th>
                                                                        <th>药品名称</th>
                                                                        <th>规格</th>
                                                                        <th>单价</th>
                                                                        <th>用法</th>
                                                                        <th>用量</th>
                                                                        <th>频次</th>
                                                                        <th>数量</th>
                                                                    </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="tab-7" class="tab-pane fade">
                            <div class="panel-body">
                                <p>费用查询</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="js/myJS/validator.js"></script>
<script src="js/myJS/input.js"></script>
<script src="js/myJS/main.js"></script>
<script src="js/myJS/medicalRecord.js"></script>
<script>
    function refreshPatientInfo() {
        let doctorID = [[${session.userID}]];
        let sendJson = {};

        sendJson['doctorID'] = doctorID;
        $.ajax({
            url: "/getAllPatientNotDiagnose",
            type: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(sendJson),
            success: function (PatientInfo) {
                $("#patientNotDiagnose tbody").empty();
                for (let i = 0; i < PatientInfo.length; i++) {
                    $("#patientNotDiagnose tbody").append(
                        '<tr>' +
                        '<td>' + PatientInfo[i].medicalRecordID + '</td>' +
                        '<td>' + PatientInfo[i].patientName + '</td>' +
                        '<td>' + PatientInfo[i].age + '</td>' +
                        '<td><button type="button" class="btn btn-sm btn-primary" onclick="diagnoseNow(this)" value="' + PatientInfo[i].registrationID + '">' +
                        '<i class="fa fa-medkit"></i></button></td>' +
                        '</tr>');
                }
            }
        });

        $.ajax({
            url: "/getAllPatientDiagnose",
            type: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(sendJson),
            success: function (PatientInfo) {
                $("#patientDiagnose tbody").empty();
                for (let i = 0; i < PatientInfo.length; i++) {
                    $("#patientDiagnose tbody").append(
                        '<tr>' +
                        '<td>' + PatientInfo[i].medicalRecordID + '</td>' +
                        '<td>' + PatientInfo[i].patientName + '</td>' +
                        '<td>' + PatientInfo[i].age + '</td>' +
                        '<td><button type="button" class="btn btn-sm btn-primary" disabled="disabled" value="' + PatientInfo[i].registrationID + '">' +
                        '<i class="fa fa-medkit"></i></button></td>' +
                        '</tr>');
                }
            }
        });
    }

    $.fn.serializeObject = function () {
        var obj = {};
        var formArray = this.serializeArray();
        for (var i = 0; i < formArray.length; i++) {
            obj[formArray[i].name] = formArray[i]['value'];
        }
        obj['registerUserID'] = [[${session.userID}]];
        return obj;
    };

    function submitMedicalRecord(obj) {
        let confirmedList = [];
        let medicalRecordState = $(obj).text();
        let registrationID = $("#diagnosingPatientRegistrationID").attr("value");

        let formData = $("#medicalRecordInfo").serializeObject();

        $("input:checkbox[name=diseaseID]").each(function () {
            let confirmed = {};
            let diseaseID = $(this).attr("value");
            confirmed["diseaseTime"] = $('input[name=' + diseaseID + ']').val();
            confirmed["diseaseID"] = diseaseID;
            confirmedList.push(confirmed);
        });
        formData["medicalRecordState"] = medicalRecordState;
        formData["medicalConfirms"] = confirmedList;
        formData["medicalRegisterId"] = registrationID;

        $.ajax({
            url: "/writeMedical",
            type: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(formData),
            success: function (ResultState) {
                $('.alert').html('提交成功').addClass('alert-warning').show().delay(1400).fadeOut();
                refreshPatientInfo();
            }
        });
    }

    function makePre() {
        let sendJson = {};
        let preName = $("button[class='btn btn-primary btn-xs active']").attr("id");
        let registrationID = $("#diagnosingPatientRegistrationID").attr("value");
        let doctorID = [[${session.userID}]];

        let drugPrescriptionDetailList = [];
        $("input:checkbox[name=drugID]").each(function () {
            let drugPrescriptionDetail = {};

            let drugID = $(this).attr("value");

            let drugPreDetailUsage = $("input[name='drugUsage" + drugID + "']").val();
            let drugPreDetailAmount = $("input[name='drugUsageNum" + drugID + "']").val();
            let drugPreDetailFreq = $("input[name='drugFreq" + drugID + "']").val();
            let drugPreDetailNum = $("input[name='drugAmount" + drugID + "']").val();

            drugPrescriptionDetail["drugId"] = drugID;
            drugPrescriptionDetail["drugPreDetailUsage"] = drugPreDetailUsage;
            drugPrescriptionDetail["drugPreDetailAmount"] = drugPreDetailAmount;
            drugPrescriptionDetail["drugPreDetailFreq"] = drugPreDetailFreq;
            drugPrescriptionDetail["drugPreDetailNum"] = drugPreDetailNum;

            drugPrescriptionDetailList.push(drugPrescriptionDetail);
        });
        sendJson["registerId"] = registrationID;
        sendJson["doctorId"] = doctorID;
        sendJson["drugPreName"] = preName;
        sendJson["drugPrescriptionDetails"] = drugPrescriptionDetailList;
        console.log(sendJson);
        $.ajax({
            url: "/makePrescription",
            type: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(sendJson),
            success: function (ResultState) {
                $('.alert').html('开立成功').addClass('alert-success').show().delay(1400).fadeOut();
            }
        });
    }
</script>
</body>